#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

#define NUM_THREADS 5
void thread_alloc_free(void *threadId) {
  int i=0;
  for (i=0; i<10; i++) {
    void *va1  = malloc(2);
    printf("Address: %p Thread: %ld\n", va1, (long)threadId);
    if (va1 != NULL) {
      free(va1);
      printf("Free Address: %p Thread: %ld\n", va1, (long)threadId);
    }
  }
}

void thread_test() {
  pthread_t threads[NUM_THREADS];
  int rc;
  long t;
  for(t=0; t<NUM_THREADS; t++){
    printf("In main: creating thread %ld\n", t);
    rc = pthread_create(&threads[t], NULL, thread_alloc_free, (void *)t);
    if (rc){
       printf("ERROR; return code from pthread_create() is %d\n", rc);
       exit(-1);
    }
  }
  /* Last thing that main() should do */
  pthread_exit(NULL);
}

int main() {
  void *va1 = malloc(352);
  void *va2 = malloc(120);
  free(va2);
  free(va1);
  va1 = malloc(5);
  free(va1);
  malloc(16);
  malloc(16);
  malloc(60);
  malloc(12);
  malloc(392);
  malloc(60);
  malloc(480);
  malloc(112);
  malloc(220);
  malloc(56);
  malloc(48);
  malloc(64);
  malloc(88);
  malloc(56);
  malloc(44);
  malloc(100);
  malloc(12);
  malloc(12);
  malloc(12);
  malloc(12);
  malloc(12);
  malloc(12);
/*
	int i = 0;
	void *ptr;
	for (; i < 5; i++) {
		ptr = malloc (15);
		printf("addr:%p\n", ptr);
	}
*/
return 0;  
}
